// pages/searchList/searchList.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nu:21

  },
  //页面跳转
  tiaozhuan: function(e){
    let item = e.currentTarget.dataset.item;
    let _str = JSON.stringify(item)

    wx.navigateTo({
      //url: e.currentTarget.dataset.path,
      url: '../search0/search0?shuju=' + _str,
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '加载中',
    })
    console.log(options.word)
    var that = this
    wx.request({
      url: 'https://jisusrecipe.market.alicloudapi.com/recipe/search?num=20&start=0&keyword=' + options.word,
      data: {
        x: '',
        y: ''
        //"pageNum": that.data.pagenum, //从数据里获取当前页数
        //"pageSize": 20, //每页显示条数
      },
      header: {
        'content-type': 'application/json', // 默认值
        "Authorization": "APPCODE 3930a9e0791146739618fd11f8ec15d4"
      },
      success(res) {
        console.log(res)
        if (res.data.result == '') {
          wx.hideLoading()
          wx.showModal({
            title: '提示',
            content: '没有你想要的菜',
            success(res) {
              if (res.confirm) {
                wx.switchTab({
                  url: '../index/index'
                })
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        } else {
          wx.hideLoading()
          that.setData({
            ztsj: res.data.result.list //合并后更新datalist
          })

        }

      }
    })
    that.setData({ shuru2: options.word })

  

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    wx.showLoading({
      title: '玩命加载中',
    })
    var that = this;
    var nu = that.data.nu
    wx.request({
      url: 'https://jisusrecipe.market.alicloudapi.com/recipe/search?num=20&keyword=' + this.data.shuru2 + "&start=" + nu,
      data: {
        x: '',
        y: ''
        //"pageNum": that.data.pagenum, //从数据里获取当前页数
        //"pageSize": 20, //每页显示条数
      },
      header: {
        'content-type': 'application/json', // 默认值
        "Authorization": "APPCODE 3930a9e0791146739618fd11f8ec15d4"
      },
      success(res) {
        if (res.data.result == '') {
          console.log("已经没有了")

        } else {
          console.log(res)
          var arr1 = that.data.ztsj;
          console.log(arr1);
          var arr2 = res.data.result.list;
          console.log(arr2);
          arr1 = arr1.concat(arr2);
          console.log(arr1)
          that.setData({
            ztsj: arr1
          })
        }

      }
    })
    that.setData({
      nu: nu + 20
    })
    wx.hideLoading();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})